export function sortByTitle(data) {
  let resultSingerList = [];
  let temp = "A";
  let index = 0;
  for (let i = 0; i < data.length; i++) {
    if (data[i].title == temp) {
      resultSingerList[index]
        ? resultSingerList[index].list.push(data[i])
        : (resultSingerList[index] = {
            title: data[i].title,
            list: [],
          });
    } else {
      temp = data[i].title;
      index++;
    }
  }
  resultSingerList = resultSingerList.filter((item) => {
    return item.list.length !== 0;
  });
  return resultSingerList;
}
export function shuffle(source) {
  const arr = source.slice();
  for (let i = 0; i < arr.length; i++) {
    const j = getRandomInt(i);
    swap(arr, i, j);
  }
  return arr;
}
export function formatTime(interval) {
  interval = Math.floor(interval);
  const minute = (Math.floor(interval / 60) + "").padStart(2, "0");
  const second = ((interval % 60) + "").padStart(2, "0");
  return `${minute}:${second}`;
}
function getRandomInt(max) {
  return Math.floor(Math.random() * (max + 1));
}
function swap(arr, left, right) {
  let temp = arr[left];
  arr[left] = arr[right];
  arr[right] = temp;
}
